﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

namespace LosConn.Web.Data
{
    public partial class DataAdd : System.Web.UI.Page
    {
        public String html = String.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //</ul></div>
                BLL.Los_Data bll = new BLL.Los_Data();
                DataTable dt = bll.GetQuestionList("").Tables[0];
                DataTable dtAns = bll.GetAnswerList("").Tables[0];
                if (dt != null && dt.Rows.Count > 0)
                {
                    StringBuilder sb = new StringBuilder(5000);
                    Int32 idx = 0;
                    foreach (DataRow dr in dt.Rows)
                    {
                        idx++;
                        if (dr["Question_Choose"].ToString().Equals("1"))
                        {
                            sb.AppendFormat("<h4 class=\"askForm\">{1}、{0}</h4>", dr["Question_Name"], idx);
                            sb.AppendFormat("<div class=\"iCheck-list askForm\"><ul class=\"inline\"><input type=\"text\" name=\"{0}\" value=\"{0}\" style=\" display: none;\" /><input type=\"text\" name=\"N{0}\" value=\"{1}\" style=\" display: none;\"  /><input type=\"text\" name=\"AI{0}\" class=\"ai\" style=\" display: none;\"  /><input type=\"text\" name=\"AN{0}\" class=\"an\" style=\" display: none;\"  />", dr["Question_ID"], dr["Question_Name"]);
                            var a = (from b in dtAns.AsEnumerable()
                                     where b.Field<Int32>("Answer_QuestionID") == Convert.ToInt32(dr["Question_ID"])
                                     select b).ToList();
                            if (a != null && a.Count() > 0)
                            {
                                for (int i = 0; i < a.Count(); i++)
                                {
                                    sb.AppendFormat("<li><input type=\"checkbox\" class=\"answer{1}\" val=\"{1}\" val1=\"{0}\"><label for=\"input-1\">{0}</label></li>", a[i]["Answer_Name"], a[i]["Answer_ID"]);
                                }
                            }
                            sb.Append("</ul></div>");
                        }
                        else if (dr["Question_Choose"].ToString().Equals("2"))
                        {
                            sb.AppendFormat("<div class=\"form-inline askForm-2\"><input type=\"text\" name=\"{2}\" value=\"{2}\" style=\" display: none;\" /><input type=\"text\" name=\"N{2}\" value=\"{1}\" style=\" display: none;\"  /><label class=\"askLabel\">{0}、{1}</label><input type=\"text\" name=\"AN{2}\"></div>", idx, dr["Question_Name"], dr["Question_ID"]);
                        }
                        else
                        {
                            sb.AppendFormat("<h4 class=\"askForm\">{1}、{0}<input type=\"text\" name=\"{2}\" value=\"{2}\" style=\" display: none;\" /><input type=\"text\" name=\"N{2}\" value=\"{0}\" style=\" display: none;\"  /></h4>", dr["Question_Name"], idx, dr["Question_ID"]);
                            sb.AppendFormat("<textarea class=\"askInput\" style=\"width:500px; height:100px;\" type=\"text\" name=\"AN{0}\"></textarea>", dr["Question_ID"]);
                        }
                    }
                    html = sb.ToString();
                }
            }
        }
    }
}